# -*- coding: utf-8 -*-
# @Time    : 2024/1/4 22:03
# @Author  : micah
# @File    : 17.session会话.py
# @Software: PyCharm


import requests

# 1.创建session对象
session = requests.Session()

headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}

response = session.get('http://www.baidu.com', headers=headers)
print('第一次请求的请求头为:', response.request.headers)
print('第一次请求的响应头为:', response.headers)

# cookie_dict = response.headers.get('Set-Cookie', '')
# print(cookie_dict)

# 返回的是RequestsCookieJar对象
print(response.cookies)
# print(dict(response.cookies))
print(requests.utils.dict_from_cookiejar(response.cookies))

response = session.get('http://www.baidu.com', headers=headers)
print('第二次请求的请求头为:', response.request.headers)





